package com.example.controller.adm;

import com.example.context.PageResult;
import com.example.service.adm.AdmProductService;
import com.example.vo.product.ProductPageReq;
import com.example.vo.product.ProductPageResp;
import com.example.vo.product.ProductReq;
import com.example.vo.product.ProductResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品管理", description = "管理商品的相关操作")
@RestController
@RequestMapping("/api/admin/product")
public class ProductController {

    @Resource
    private AdmProductService productService;

    @GetMapping
    @Operation(summary = "分页查询商品列表", description = "分页查询商品列表")
    public PageResult<ProductPageResp> findAll(@Valid ProductPageReq req) {
        return productService.findAll(req);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id查询商品", description = "根据id查询商品")
    public ProductResp findById(@PathVariable("id") Long id) {
        return productService.findById(id);
    }

    @GetMapping("/status/{id}")
    @Operation(summary = "修改商品状态", description = "修改商品状态")
    public void changeStatusById(@PathVariable("id") Long id) {
        productService.changeStatusById(id);
    }

    @PostMapping
    @Operation(summary = "新增商品", description = "新增商品")
    public void add(@Valid @RequestBody ProductReq req) {
        productService.add(req);
    }

    @PutMapping
    @Operation(summary = "修改商品", description = "修改商品")
    public void update(@Valid @RequestBody ProductReq req) {
        productService.updateProduct(req);
    }

    @DeleteMapping
    @Operation(summary = "删除商品", description = "删除商品",
            parameters = {
                    @Parameter(name = "ids", description = "商品id数组", required = true)
            })
    public void delete(@RequestParam Long[] ids) {
        productService.delete(ids);
    }

}
